#pragma strict
////////////////////////////////////////////////////////////////////////////////////
///加入 溶解效果.
////////////////////////////////////////////////////////////////////////////////////
//溶解材质.
var dissolveMat:Material;

var dissolveAmount:float = 1;
var dissolveTime:float = 3;
private var dissolveSpeed:float;

private var r:Renderer;

var root:Transform;
var materialChanger:MaterialChangerMotor;

function Start () {
	r = renderer;
	if(! root)
		root = transform;
	
	materialChanger = new MaterialChangerMotor(root,[dissolveMat],typeof(Renderer));
}

function StartWork(){
	materialChanger.AddMat();
	dissolveSpeed = dissolveAmount / dissolveTime;
}

function StopWork(){
	materialChanger.RemoveMat();
	dissolveAmount = 0;
}

function Update(){
	if(dissolveAmount > 0){
		dissolveAmount -= dissolveSpeed * Time.deltaTime;
		dissolveMat.SetFloat("_DissolveAmount",dissolveAmount);
	}else{
		StopWork();
	}
}